//
//  TransQICheckViewController.m
//  Qihuo
//
//  Created by Vencoo on 14-1-3.
//  Copyright (c) 2014年 Vencoo. All rights reserved.
//

#import "TransQICheckViewController.h"
#import "TransCheckCell.h"
@interface TransQICheckViewController ()

@end

@implementation TransQICheckViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    self.checkURL = resultOfTrans;
    self.checkNames = @[@"开关温度",@"噪音",@"冷却风扇",@"LED显示屏",@"清洁",@"A相电流",@"B相电流",@"C相电流",@"备注"];
    [super viewDidLoad];
    self.title = @"变频器巡检记录";

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *identifier = [NSString stringWithFormat:@"cell%d",indexPath.row];
    TransCheckCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell)
    {
        cell = [[TransCheckCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        if (self.floorCheckDatas.count > 0)
        {
            NSArray *checkDatas = [self.floorCheckDatas objectAtIndex:indexPath.row];
            for (int i = 0; i < checkDatas.count; i ++)
            {
                NSDictionary *checkDic = [checkDatas objectAtIndex:i];
                NSString *checkResult = [NSString stringWithFormat:@"%@",[checkDic objectForKey:@"result"]];
                UIControl *control = [UIControl new];
                CGSize mySz;
                if ([checkResult isEqualToString:@"0"])
                {
                    UIImage *rightImage = [UIImage imageNamed:@"正常"];
                    mySz = rightImage.size;
                    UIImageView *rightView = [[UIImageView alloc]initWithImage:rightImage];
                    control = (UIControl*)rightView;
                    control.frame = CGRectMake(cell.longFloorNameLb.frame.origin.x + cell.longFloorNameLb.frame.size.width + i * (900/(checkDatas.count + 1)),cell.longFloorNameLb.frame.origin.y, mySz.width, mySz.height);
                }
                else
                {
                    UILabel *resultLb = [UILabel new];
                    resultLb.text = checkResult;
                    resultLb.font = [UIFont systemFontOfSize:15];
                    mySz = [[NSString stringWithFormat:@"啊啊啊啊啊啊"] sizeWithFont:resultLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
                    resultLb.numberOfLines = 2;
                    resultLb.lineBreakMode = 0;
                    if (checkResult.length < 7)
                    {
                        resultLb.frame = CGRectMake(100 + i * (900/(checkDatas.count + 1)),cell.longFloorNameLb.frame.origin.y, mySz.width, mySz.height);
                    }
                    else
                    {
                        resultLb.frame = CGRectMake(100 + i * (900/(checkDatas.count + 1)),cell.longFloorNameLb.frame.origin.y, mySz.width, mySz.height*2);
                        cell.frame = CGRectMake(0, 0, cell.frame.size.width ,resultLb.frame.size.height * 1.5);
                    }
                    resultLb.textAlignment = 1;
                    control = (UIControl*)resultLb;
                }
                [cell addSubview:control];
            }
            
        }
        
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (self.floorNames.count > 0) {
        cell.longFloorNameLb.text = [self.floorNames objectAtIndex:indexPath.row];
    }
    if (self.floorRemarks.count > 0) {
        cell.resultLb.text = [self.floorRemarks objectAtIndex:indexPath.row];
    }
    return cell;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
